﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using ProjectManage.Application.System.Services;
using ProjectManage.Core.Entity.SYS;

namespace ProjectManage.Application.System
{
    /// <summary>
    /// 系统服务接口
    /// </summary>
    public class SystemAppService : IDynamicApiController
    {
        private readonly ISystemService _systemService;
        public SystemAppService(ISystemService systemService)
        {
            _systemService = systemService;
        }
        #region  用户
        /// <summary>
        /// 新增用户
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddUser")]
        public async Task AddUserAsync(AddUserDto input)
        {
           await _systemService.AddUserAsync(input);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <returns></returns>
        [HttpPost("DeleteMutiUserAsync")]
        public async Task DeleteMutiUserAsync(List<DeleteDto> input)
        {
            await _systemService.DeleteMutiUserAsync(input);
        }

        /// <summary>
        /// 更新用户
        /// </summary>
        /// <returns></returns>
        [HttpPost("UpdateUserAsync")]
        public async Task UpdateUserAsync(UpdateUserDto input)
        {
            await _systemService.UpdateUserAsync(input);
        }

        /// <summary>
        /// 查询用户
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryUserAsync")]
        public async Task<PagedList<QueryUserDto>> QueryUserAsync(QueryParameter input)
        {
            return await _systemService.QueryUserAsync(input);
        }
        #endregion
     
        #region 登录
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost("Login")]       
        public Task<TokenModel> LoginAsync(LoginDto input)
        {
            return _systemService.LoginAsync(input);
        }

        /// <summary>
        /// 三方登录
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost("ThreeLoginAsync")]
        public Task<TokenModel> ThreeLoginAsync(LoginDto input)
        {
            return _systemService.ThreeLoginAsync(input);
        }
        #endregion

        #region 角色相关操作
        /// <summary>
        /// 新增角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddRoleAsync")]
        public async Task AddRoleAsync(AddRoleDto input)
        {
            await _systemService.AddRoleAsync(input);
        }

        /// <summary>
        /// 更新角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("UpdateRoleAsync")]
        public async Task UpdateRoleAsync(UpdateRoleDto input)
        {
            await _systemService.UpdateRoleAsync(input);
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("DeleteMutiRoleAsync")]
        public async Task DeleteMutiRoleAsync(List<DeleteDto> input)
        {
            await _systemService.DeleteMutiRoleAsync(input);
        }

        /// <summary>
        /// 查询角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryRoleAsync")]
        public async Task<PagedList<QueryRoleDto>> QueryRoleAsync(QueryParameter input)
        {
            return await _systemService.QueryRoleAsync(input);
        }
        #endregion

        #region 数据字典
        /// <summary>
        /// 新增数据字典
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddDictionaryAsync")]
        public async Task AddDictionaryAsync(AddDictionaryDto input)
        {
            await _systemService.AddDictionaryAsync(input);
        }

        /// <summary>
        /// 更新数据字典
        /// </summary>
        /// <returns></returns>
        [HttpPost("UpdateDictionaryAsync")]
        public async Task UpdateDictionaryAsync(UpdateDictionaryDto input)
        {
            await _systemService.UpdateAsync<SysDictionary, UpdateDictionaryDto>(input);
        }

        /// <summary>
        /// 删除数据字典
        /// </summary>
        /// <returns></returns>
        [HttpPost("DeleteMutiDictionaryAsync")]
        public async Task DeleteMutiDictionaryAsync(List<DeleteDto> input)
        {
            await _systemService.DeleteMutiAsync<SysDictionary>(input);
        }

        /// <summary>
        /// 查询数据字典
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryDictionaryAsync")]
        public async Task<PagedList<QueryDictionaryDto>> QueryDictionaryAsync(QueryParameter input)
        {
            return await _systemService.QueryDictionaryAsync(input);
        }

        /// <summary>
        /// 查询数据字典根据类别
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryDictionaryByTypeAsync")]
        public async Task<List<SelectedItem>> QueryDictionaryByTypeAsync(string input)
        {
            return await _systemService.QueryDictionaryByTypeAsync(input);
        }

        #endregion

        #region 菜单
        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddMenuAsync")]
        public async Task AddMenuAsync(AddMenuDto input)
        {
            await _systemService.AddMenuAsync(input);
        }

        /// <summary>
        /// 更新菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("UpdateMenuAsync")]
        public async Task UpdateMenuAsync(UpdateMenuDto input)
        {
            await _systemService.UpdateAsync<SysMenu, UpdateMenuDto>(input);
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("DeleteMutiMenuAsync")]
        public async Task DeleteMutiMenuAsync(List<DeleteDto> input)
        {
            await _systemService.DeleteMutiAsync<SysMenu>(input);
        }

        /// <summary>
        /// 查询菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryButtonsByAccountAsync")]
        public async Task<List<QueryMenuDto>> QueryButtonsByAccountAsync([FromQuery]string Account)
        {
            return await _systemService.QueryButtonsByAccountAsync(Account);
        }

        /// <summary>
        /// 查询菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryMenuAsync")]
        public async Task<List<QueryMenuDto>> QueryMenuAsync()
        {
            return await _systemService.QueryMenuAsync();
        }
        #endregion

        #region 用户角色关系
        /// <summary>
        /// 新增用户角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddUserRoleAsync")]
        public async Task AddUserRoleAsync(AddUserRoleDto input)
        {
            await _systemService.AddUserRoleAsync(input);
        }

        /// <summary>
        /// 更新用户角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("UpdateUserRoleAsync")]
        public async Task UpdateUserRoleAsync(UpdateUserRoleDto input)
        {
            await _systemService.UpdateAsync<SysUserRole, UpdateUserRoleDto>(input);
        }

        /// <summary>
        /// 删除用户角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("DeleteMutiUserRoleAsync")]
        public async Task DeleteMutiUserRoleAsync(List<DeleteDto> input)
        {
            await _systemService.DeleteMutiAsync<SysUserRole>(input);
        }

        /// <summary>
        /// 查询用户角色
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryUserRoleAsync")]
        public async Task<PagedList<QueryUserRoleDto>> QueryUserRoleAsync(QueryParameter input)
        {
            return await _systemService.QueryUserRoleAsync(input);
        }
        #endregion


        #region 角色菜单
        /// <summary>
        /// 新增角色菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddRoleMenuAsync")]
        public async Task AddRoleMenuAsync(AddRoleMenuDto input)
        {
            await _systemService.AddRoleMenuAsync(input);
        }

        /// <summary>
        /// 更新角色菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("UpdateRoleMenuAsync")]
        public async Task UpdateRoleMenuAsync(UpdateRoleMenuDto input)
        {
            await _systemService.UpdateAsync<SysRoleMenu, UpdateRoleMenuDto>(input);
        }

        /// <summary>
        /// 删除角色菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("DeleteMutiRoleMenuAsync")]
        public async Task DeleteMutiRoleMenuAsync(List<DeleteDto> input)
        {
            await _systemService.DeleteMutiAsync<SysRoleMenu>(input);
        }

        /// <summary>
        /// 查询角色菜单
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryRoleMenuAsync")]
        public async Task<PagedList<QueryRoleMenuDto>> QueryRoleMenuAsync(QueryParameter input)
        {
            return await _systemService.QueryRoleMenuAsync(input);
        }


        /// <summary>
        /// 查询菜单根据角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("QueryMenusByRoleCodeAsync")]
        public async Task<List<QueryMenuDto>> QueryMenusByRoleCodeAsync([FromQuery]string RoleCode)
        {
            return await _systemService.QueryMenusByRoleCodeAsync(RoleCode);
        }

      
        /// <summary>
        /// 查询菜单根据账号
        /// </summary>
        /// <param name="Account"></param>
        /// <param name="AppCode"></param>
        /// <returns></returns>
        [HttpPost("QueryMenusByAccountAsync")]
        public async Task<List<QueryMenuItem>> QueryMenusByAccountAsync([FromQuery] string Account, [FromQuery] string AppCode)
        {
            return await _systemService.QueryMenusByAccountAsync(Account, AppCode);
        }
        #endregion
    }
}